<template>
	<view class="container">
		<unicloud-db ref="udb" v-slot:default="{data, pagination, loading, hasMore, error}" orderby="publish_date desc"
			:collection="collectionList" field="article_id,publish_date">
			<view v-if="error">{{error.message}}</view>
			<view v-else-if="data">
				<uni-list>
					<uni-list-item v-for="(item, index) in data" :key="index" showArrow :clickable="true"
						@click="handleItemClick(item.article_id[0]._id)">
						<template v-slot:body>
							<view class="content">
								<view class="title">
									{{item.article_id[0].title}}
								</view>
								<view class="releasetime">
									<uni-dateformat :date="item.publish_date" :threshold="[60000, 3600000]"
										format="yyyy年MM月dd hh:mm:ss"></uni-dateformat>
								</view>
							</view>
						</template>
					</uni-list-item>
				</uni-list>
			</view>
			<uni-load-more :status="loading?'loading':(hasMore ? 'more' : 'noMore')"></uni-load-more>
		</unicloud-db>
	</view>
</template>

<script>
	const db = uniCloud.database()
	export default {
		data() {
			return {
				collectionList: [
					db.collection("cloud_fishCircle-like").where(`user_id==$cloudEnv_uid`).getTemp(),
					db.collection("cloud_fishCircle-article").field("_id,title").getTemp()
				],
				loadMore: {
					contentdown: '',
					contentrefresh: '',
					contentnomore: ''
				}
			}
		},
		onLoad() {
			uni.setNavigationBarTitle({
				title: '我的点赞'
			});
		},
		onPullDownRefresh() {
			this.$refs.udb.loadData({
				clear: true
			}, () => {
				uni.stopPullDownRefresh()
			})
		},
		onReachBottom() {
			this.$refs.udb.loadMore()
		},
		methods: {
			handleItemClick(id) {
				uni.navigateTo({
					url: '/pages/detail/detail?id=' + id
				})
			},
		}
	}
</script>

<style lang="scss">
	.container {
		.content {
			.title {
				@include text-omission(1);
				font-size: 34rpx;
			}

			.releasetime {
				color: #888;
				font-size: 24rpx;
			}
		}
	}
</style>